package com.sx.micowell.module.smartDevice;

import androidx.lifecycle.Observer;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.example.mvvm.base.data.DataBindingConfig;
import com.gyf.immersionbar.ImmersionBar;
import com.sx.micowell.BR;
import com.sx.micowell.R;
import com.sx.micowell.databinding.ActDeviceRegisterBinding;
import com.sx.micowell.framework.app.IntentKey;
import com.sx.micowell.framework.app.MyActivity;
import com.sx.micowell.framework.arouth.RoutePath;
import com.sx.micowell.framework.model.smartDevice.SmartDeviceRegisterModel;

/**
 * @Author: YY
 * @Time: 2021/9/16
 * @Describe 智能设备 - 账号注册
 */
@Route(path = RoutePath.SMART_DEVICE_REGISTER)
public class DeviceRegisterActivity extends MyActivity<ActDeviceRegisterBinding> {

    @Autowired(name = IntentKey.TYPE)
    int type = 1;

    private SmartDeviceRegisterModel viewModel;

    @Override
    protected void initViewModel() {
        super.initViewModel();
        viewModel = getActivityScopeViewModel(SmartDeviceRegisterModel.class);
    }

    @Override
    protected DataBindingConfig getDataBindingConfig() {
        return new DataBindingConfig(R.layout.act_device_register, BR.viewModel, viewModel);
    }

    @Override
    public void initView() {
        // 设置状态栏字体颜色
        ImmersionBar.with(this).statusBarDarkFont(true)
                .fitsSystemWindows(true).init();
    }

    @Override
    public void initData() {
        viewModel.mRegisterType = type;
        if (type != 1) {
            getBinding().tvTitle.setText("重置密码");
            getBinding().tvCommit.setText("确定");
        }
    }

    @Override
    protected void initViewObservable() {
        super.initViewObservable();
        viewModel.sendCodeEvent.observe(this, new Observer<Void>() {
            @Override
            public void onChanged(Void unused) {
                getBinding().tvCountDown.start();
            }
        });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        getBinding().tvCountDown.stop();
    }
}
